package com.jiaai.web.zfp_back.member;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.member.api.IYukuApi;
import com.jiaai.util.RestResultGenerator;
import org.springframework.web.bind.annotation.*;

/**
 * class_name:ZBYukuController
 * describe:TODO
 * create_user:张昉平
 * create_date:2018/1/6
 * create_date:15:45
 */
@RestController
@RequestMapping("/api/v1/admin/yuku")
public class ZBYukuController {

    @Reference
    private IYukuApi iYukuApi;

    @GetMapping("/list")
    public Object list(@RequestParam Integer curr, String query){
        return RestResultGenerator.genSuccessResult(iYukuApi.getAll(curr, query));
    }

    @PostMapping("/saveoredit")
    public Object saveOrEdit(Integer yuId, String content){
        iYukuApi.saveOrEdit(yuId, content);
        return RestResultGenerator.genSuccessResult("成功");
    }

    @PostMapping("/delete/{id}")
    public Object delete(@PathVariable("id") Integer id){
        iYukuApi.delete(id);
        return RestResultGenerator.genSuccessResult("成功");
    }

//    @PostMapping("/runJob")
//    public Object runJob(@RequestParam Integer robotId, @RequestParam Integer liveId){
//        try {
//            iRobotApi.runRobot(robotId, liveId);
//            return RestResultGenerator.genSuccessResult("操作成功");
//        }catch (Exception e){
//            if (e.getMessage().equals("DUPLICATE")) return RestResultGenerator.genErrorResult(600, "该房间已经有该机器人啦!");
//            e.printStackTrace();
//            throw new RuntimeException("服务器挂了");
//        }
//    }

//    @PostMapping("/removeRobot")
//    public Object removeRobot(@RequestParam Integer robotId, @RequestParam Integer liveId){
//        iRobotApi.removeRunRobot(robotId, liveId);
//        return RestResultGenerator.genSuccessResult("操作成功");
//    }
//
//    //移除一个机器人的所有正运行的工作
//    @PostMapping("/delRobotJobs")
//    public Object delRobotJobs(@RequestParam Integer robotId){
//        iRobotApi.removeOneRobotAllJobs(robotId);
//        return RestResultGenerator.genSuccessResult("移除成功");
//    }

}
